/* ASCII D2 - init.c
   Bogdan Filipchuk
   */
   
#include main.h

#define WIDTH 640
#define HEIGHT 300
#define COLOR_DEPTH 32

bool D2_ASCII.init(){
   // Create Display
   if( SDL_Init(SDL_INIT_EVERYTHING) < 0){
      return false;
   }
   
   // Setup OpenGL attributes
   SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
   SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);

   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
   SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,32);

   SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,8);
   SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,8);
   SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,8);
   SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,8);

   SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
   SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,2);
   
   // Create SDL window
   if( (Surf_Display = SDL_SetVideoMode( WIDTH, HEIGHT,
         COLOR_DEPTH, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL )) == NULL ){
      return false;
   }
   
   
   //Enable 2D mode for Open GL
   
   glClearColor(0, 0, 0, 0); // glClearColor((128.0f / 255.0f), 1.0f, 1.0f, 1.0f); //Cyan color
   glClearDepth(1.0f);
   
   glViewport(0, 0, 640, 300);
   
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   glOrtho(0, 640, 300, 0, 1, -1);

   glMatrixMode(GL_MODELVIEW);

   glEnable(GL_TEXTURE_2D);

   glLoadIdentity();
   
   
   
   
   
   glDisable( GL_DEPTH_TEST );
   glMatrixMode( GL_PROJECTION );
   glLoadIdentity();
   
   glOrtho( 0, 640, 300, 0 );
   
   
   return true;
}